package com.ssyc.gsk_master.activity;

import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.ssyc.common.base.BaseActivity;
import com.ssyc.common.manager.BqaManager;
import com.ssyc.common.manager.PickChooseManager;
import com.ssyc.common.manager.StateBarManager;
import com.ssyc.gsk_master.R;
import com.ssyc.gsk_master.adapter.ShowImgRvAdapter;
import com.ssyc.gsk_master.bean.NoticeInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * 活动详情界面
 * Created by Administrator on 2018/6/25 0025.
 */

public class MasterNoticeDetailsActivity extends BaseActivity implements View.OnClickListener {

    //返回键
    private RelativeLayout rlBack;

    //标题
    private TextView tvTitle;

    //标题
    private TextView tvName;

    //时间
    private TextView tvTime;

    //公告内容
    private TextView tvContent;

    //展示图片的列表控件
    private RecyclerView rv;

    //模拟的图片数据,实际是从页面数据对象中取
    private List<String> mUrls;


    //页面数据
    private NoticeInfo.ListBean info;

    //头视图
    private View headView;

    @Override
    protected boolean isNeedShowTitle() {
        return false;
    }

    @Override
    protected String setTitleText() {
        return null;
    }

    @Override
    protected int getContentLayout() {
        return R.layout.master_activity_notice_details;
    }

    @Override
    protected void init() {

        showContent();

        //获取传递的对象,页面数据对象
        initIntent();

        //初始化视图
        initView();

        //配置状态栏颜色
        initStateColor();

        //根绝页面对象设置数据
        setData();
    }

    /**
     * 配置状态栏颜色的方法
     */
    private void initStateColor() {
        //设置6.0以后沉浸状体栏的问题
        StateBarManager.setBarWithUltimateBar(this, getResources().getColor(com.ssyc.common.R.color.titlebg),
                getResources().getColor(com.ssyc.common.R.color.nav_color));
    }

    /**
     * 初始化视图
     */
    public void initView() {
        rlBack = findViewById(R.id.rl_back);
        rlBack.setOnClickListener(this);
        rv = findViewById(R.id.rv);
        headView = View.inflate(this, R.layout.master_headview_notice, null);
        tvTitle = findViewById(R.id.tv_title);
        tvName = headView.findViewById(R.id.tv_name);
        tvTime = headView.findViewById(R.id.tv_time);
        tvContent = headView.findViewById(R.id.tv_content);
        tvTitle.setText(info.getTag());
    }

    /**
     * 获取传递的对象,页面数据对象
     */
    private void initIntent() {
        info = (NoticeInfo.ListBean) getIntent().getSerializableExtra("data");

    }

    /**
     * 根据页面对象设置数据的方法
     */
    private void setData() {

        if (info != null) {
            tvName.setText(info.getTag());
            tvTime.setText(info.getTime());
            tvContent.setText(info.getContent());
            //设置图片的列表
            mUrls = new ArrayList<>();
            if (!TextUtils.isEmpty(info.getPicture1())) {
                mUrls.add(info.getPicture1());
            }
            if (!TextUtils.isEmpty(info.getPicture2())) {
                mUrls.add(info.getPicture2());
            }
            if (!TextUtils.isEmpty(info.getPicture3())) {
                mUrls.add(info.getPicture3());
            }
            if (!TextUtils.isEmpty(info.getPicture4())) {
                mUrls.add(info.getPicture4());
            }
            if (!TextUtils.isEmpty(info.getPicture5())) {
                mUrls.add(info.getPicture5());
            }
            if (!TextUtils.isEmpty(info.getPicture6())) {
                mUrls.add(info.getPicture6());
            }
            if (!TextUtils.isEmpty(info.getPicture7())) {
                mUrls.add(info.getPicture7());
            }
            if (!TextUtils.isEmpty(info.getPicture8())) {
                mUrls.add(info.getPicture8());
            }
            if (!TextUtils.isEmpty(info.getPicture9())) {
                mUrls.add(info.getPicture9());
            }
            ShowImgRvAdapter adapter = new ShowImgRvAdapter(this, R.layout.master_rv_img, mUrls);
            adapter.addHeaderView(headView);
            BqaManager.setRv(null, this, adapter, rv);
            adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                    PickChooseManager.startShowBigActivity(MasterNoticeDetailsActivity.this, mUrls, position);
                }
            });
        }
    }


    /**
     * 点击事件
     *
     * @param v
     */
    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.rl_back) {
            //返回
            finish();
        }
    }
}
